#include "plugin2.h"

#include "pluginwidget.h"

#include <QDebug>

class Plugin2Private {
public:
  Plugin2Private(Plugin2 *q) : q_ptr(q) {}
  ~Plugin2Private() {}

private:
  Plugin2 *const q_ptr;
  Q_DECLARE_PUBLIC(Plugin2)

  PluginWidget *pluginWidget{nullptr};
};

Plugin2::Plugin2(QObject *parent)
    : QObject(parent), d_ptr(new Plugin2Private(this)) {}

Plugin2::~Plugin2() { delete d_ptr; }

QWidget *Plugin2::widget() {
  Q_D(Plugin2);
  if (!d->pluginWidget)
    d->pluginWidget = new PluginWidget;

  return d->pluginWidget;
}

void Plugin2::receiveMessage(PluginMessage message) {
  Q_D(Plugin2);
  qDebug() << Q_FUNC_INFO << " " << message.message;
}

PluginMessage Plugin2::handleMessage(PluginMessage message) {
  Q_D(Plugin2);
  qDebug() << Q_FUNC_INFO << " " << message.message;

  PluginMessage pluginMessage;
  pluginMessage.src = "plugin2";
  pluginMessage.dst = message.src;
  if (message.message == "getLabel") {
    pluginMessage.message = d->pluginWidget->getLabel();
  }

  return pluginMessage;
}
